home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Serious Software
/
Cherwell Scientific Demos
/
pro Fit
/
pro Fit 5.0 demo (fpu).sea
/
pro Fit 5.0 demo (fpu)
/
External Modules
/
External modules sources
/
Pascal
/
Lissajous.p
< prev
next >
Wrap
Text File
|
1994-09-28
|
6KB
|
204 lines
{************************************************************************************}
{ Lissajous.p }
{ }
{ }
{ Version 26.9.94 }
{************************************************************************************}
unit user;
interface
uses
proFit_interface;
procedure main (selector: integer; pb: ExtModulesParamBlockPtr);
implementation
{ note: MPW users must make sure that the procedure main is at the beginning of the compiled code }
{ under Think Pascal, this is cared for by the compiler }
{ We let main call a function mainMain to make sure that the code starts with a jump to }
{ our entry point even when compiling under MPW Pascal }
procedure mainMain (selector: integer; pb: ExtModulesParamBlockPtr);
forward;
procedure main (selector: integer; pb: ExtModulesParamBlockPtr);
begin
mainMain(selector, pb);
end;
{************************************************************************************}
procedure SetUp (var moduleKind: integer; { set moduleKind to isFunction or isProgram }
var name: Str255; { the name of the program or function }
var requiredGlobals: longint; { the number of bytes to be allocated in ExtModulesParamBlock.globals }
{ set requiredGlobals to 0 if you don't use this feature }
pb: ExtModulesParamBlockPtr); { the complete parameter block passed by pro Fit to the }
{ routines defined in this file. In most cases it can be ignored }
{ SetUp is called once when the external module is linked to pro Fit }
begin
moduleKind := isProgram;
name := 'Lissajous';
requiredGlobals := 0;
end;
{************************************************************************************}
procedure InitializeProg (pb: ExtModulesParamBlockPtr);
{ Can be left emtpy if not needed. }
{ called when the external module is linked to proFit after SetUp was called }
{ can be used to inititialize global variables, etc. }
begin
{ initialize default values: }
pb^.V[1] := 3; { the frequency along x }
pb^.V[2] := 4; { the frequency along y }
pb^.V[3] := 0.5; { the step width }
pb^.V[4] := 500; { the number of points }
end;
{************************************************************************************}
procedure Run (pb: ExtModulesParamBlockPtr);
{ pro Fit calls this function when the name of the program is chosen from the }
{ Run Program submenu in the menu Calc }
var
s1, s2, s3, s4: str255; { buffers for input }
ex1, ex2, ex3, ex4: extended; { dto }
r: inputRec; { dto }
i: integer;
angle: extended;
begin
{ get the parameters from user, for this we prepare the inputRec r }
ex1 := pb^.v[1]; { default values are stored in v[..] }
s1 := 'Frequency x';
r[1].x := pointer(@ex1);
r[1].s := pointer(@s1);
ex2 := pb^.v[2];
s2 := 'Frequency y';
r[2].x := pointer(@ex2);
r[2].s := pointer(@s2);
ex3 := pb^.v[3];
s3 := 'Step [rad]';
r[3].x := pointer(@ex3);
r[3].s := pointer(@s3);
ex4 := pb^.v[4];
s4 := 'Number of points';
r[4].x := pointer(@ex4);
r[4].s := pointer(@s4);
if InputBox(4, r) then
exit(run);
if ex4 > maxint then { make sure ex4 can be cast to an integer }
ex4 := maxint
else if ex4 < 0 then
ex4 := 0;
pb^.v[1] := ex1; { defaults for next time }
pb^.v[2] := ex2;
pb^.v[3] := ex3;
pb^.v[4] := ex4;
CreateNewGraf(-1, 1, -1, 1, false, false); {create a new graph}
{ start drawing the curve: }
newCurve(0.5, 1, 1, 'Lissajous'); { thickness 0.5, no dash, black }
grMoveto(1, 0); { move to the start point }
angle := 0;
for i := 1 to round(ex4) do
begin
grLineto(cos(ex1 * angle), sin(ex2 * angle));
angle := angle + ex3;
end; { for i }
end; { run }
{************************************************************************************}
procedure CleanUp (pb: ExtModulesParamBlockPtr);
{ called when the function or program is removed from pro Fit's menus }
{ in most cases, this function can be empty }
begin
end;
{***********************************************************************************************}
{ This is the main procedure through which all calls to the external module go. }
{ Main takes care of calling the right procedure with the right parameters depending on }
{ the value of "selector". }
{ You don't need to touch this procedure }
procedure mainMain (selector: integer; pb: ExtModulesParamBlockPtr);
begin
Startup(pb);
case selector of
kSetup:
begin
pb^.requiredGlobals := 0;
pb^.versionNumber := VERSIONNUMBER;
if sizeof(extended) = 10 then
pb^.codeType := CPU68noFPU
else if sizeof(extended) = 12 then
pb^.codeType := CPU68FPU
else
pb^.codeType := CPUPowerPC;
SetUp(pb^.moduleKind, pb^.name, pb^.requiredGlobals, pb);
end;
progInitialize:
InitializeProg(pb);
progRun:
Run(pb);
{• funcInitialize: •}
{• begin•}
{• pb^.hasDerivatives := false;•}
{• InitializeFunc(pb^.hasDerivatives, pb^.descr1, pb^.descr2, pb^.numberOfParams, pb^.a0, pb);•}
{• end;•}
{• funcCheck: •}
{• pb^.answer := ord(Check(pb^.paramNo, pb^.a0, pb));•}
{• funcFirst: •}
{• First(pb^.a^, pb);•}
{• funcFunc: •}
{• Func(pb^.x^, pb^.a^, pb^.y^, pb);•}
{• funcDerivatives: •}
{• Derivatives(pb^.x^, pb^.a^, pb^.dyda^, pb);•}
{• funcLast: •}
{• Last(pb);•}
kcleanup:
CleanUp(pb);
otherwise
end;
end;
{--------------------------------------------------------------------------------------------------------}
end.